package com.linkhub.oms.dao.mpservice.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkhub.oms.dao.mapper.OrderOriginBusinessStatusEntityMapper;
import com.linkhub.oms.dao.mpservice.IOrderOriginBusinessStatusService;
import com.linkhub.oms.entity.OrderOriginBusinessStatusEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author Jaycle
 * @version 1.0.0
 * @Description gf.java
 * @createTime 2024/07/02 22:18
 */
@Service
@Slf4j
public class OrderOriginBusinessStatusServiceImpl extends ServiceImpl<OrderOriginBusinessStatusEntityMapper, OrderOriginBusinessStatusEntity> implements IOrderOriginBusinessStatusService {

    @Override
    public OrderOriginBusinessStatusEntity getOriginStatus( String sysOrderId ) {
        return lambdaQuery()
                .eq(OrderOriginBusinessStatusEntity::getSysOrderId, sysOrderId)
                .one();
    }

    @Override
    public boolean deleteOriginStatusRecord( String sysOrderId ) {
        return lambdaUpdate()
                .eq(OrderOriginBusinessStatusEntity::getSysOrderId, sysOrderId)
                .remove();
    }

    @Override
    public void saveOriginStatusRecord( String sysOrderId, Integer curBizStatus ) {
        LocalDateTime now = LocalDateTime.now();

        // 删除原记录
        this.deleteOriginStatusRecord(sysOrderId);

        // 准备实体对象
        OrderOriginBusinessStatusEntity entity = new OrderOriginBusinessStatusEntity();
        entity.setSysOrderId(sysOrderId);
        entity.setOriginCustomerBusinessStatus(curBizStatus);
        entity.setCreatedTime(now);
        entity.setUpdateTime(now);

        this.save(entity);
    }
}
